/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BuktiTransaksi;

import Koneksi.koneksi;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.naming.spi.DirStateFactory.Result;
import javax.swing.JOptionPane;

/**
 *
 * @author asus
 */
public class BuktiTransaksiController {

    private Connection conn = null;
    private static BuktiTransaksiController buktitransaksicontroller;

    public BuktiTransaksiController(Connection conn) {
        this.conn = conn;
    }

    public static BuktiTransaksiController getTransaksiController() throws SQLException, FileNotFoundException, IOException {
//        koneksi con = new koneksi();
        if (buktitransaksicontroller == null) {
            buktitransaksicontroller = new BuktiTransaksiController(koneksi.getDBConnection());

        }
        return buktitransaksicontroller;
    }

    public List<BuktiTransaksi> getNoTransaksiPenj(String noTrans) throws SQLException {

        conn.setAutoCommit(false);
        ResultSet result = null;
        PreparedStatement prep = null;
        String sql = "select NOTRANSAKSIPENJUALAN, WAKTU, NOMORHP, NOMINAL, HARGAPENJUALAN "
                + "from PENJUALANPULSA where NOTRANSAKSIPENJUALAN= '" + noTrans+"'";
        prep = conn.prepareStatement(sql);
        result = prep.executeQuery();
        List<BuktiTransaksi> buktiTrans = new ArrayList<BuktiTransaksi>();
//        }
        while (result.next()) {
            BuktiTransaksi bukti = new BuktiTransaksi();
            BuktiTransaksi.setNo_transaksi_penj(result.getString("NOTRANSAKSIPENJUALAN"));
            bukti.setWaktu(result.getString("WAKTU"));
            bukti.setHarga_penjualan(result.getLong("HARGAPENJUALAN"));
            bukti.setNoHP(result.getString("NOMORHP"));
            bukti.setNominal(result.getLong("NOMINAL"));
            buktiTrans.add(bukti);
        }
        return buktiTrans;
    }
}
